﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using lib.Twitter;


namespace lib
{

    // Singleton pattern to manage Stream List
    // Built on Design by Jóhann Haukur.
    public sealed class ManageStreamList
    {

        public BindingList<StatusUser> tStatusUser 
        {
            get
            {
                List<Status> st = lib.Twitter.TwitterLinq.getOrderedStatuses();

                var results = new BindingList<StatusUser> ();
                for (int i = 0; i < st.Count; i++)
                {
                    results.Insert(i, new StatusUser(st[i], lib.Twitter.TwitterLinq.getTwitterUserByStatus(st[i])));
                }
                return results;

            }
        }

        
        

        public static ManageStreamList getInstance
        {
            get
            {
                try
                {
                    return NestedManageStreamList.ul;
                }
                catch (TypeInitializationException ex)
                {
                    //Todo: handle differently?
                    // NB: TypeInitializationException thrown when exception in initializing.
                    throw ex;
                }
            }
        }

        // Use inner class to guarantee thread safe singleton.
        // See http://www.yoda.arachsys.com/csharp/singleton.html
        internal class NestedManageStreamList
        {
            static NestedManageStreamList()
            {
                ; // Pass
            }

            internal static readonly ManageStreamList ul = new ManageStreamList();

        }

    }
}
